package com.gdssoft.pdaweb.service.ws.impl;

import javax.jws.WebService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.gdssoft.core.util.DateUtil;
import com.gdssoft.pdaweb.dao.CrmWorkOrderDao;
import com.gdssoft.pdaweb.model.CrmWorkOrder;
import com.gdssoft.pdaweb.service.ws.CrmWorkOrderService;
import common.Logger;

@WebService(endpointInterface = "com.gdssoft.pdaweb.service.ws.CrmWorkOrderService", 
		serviceName="CrmWorkOrderService", targetNamespace="http://gdssoft.foxconn.com/")
public class CrmWorkOrderServiceImpl implements CrmWorkOrderService {
	
	private CrmWorkOrderDao dao;
	private transient final Log logger = LogFactory.getLog(getClass());
	
	public CrmWorkOrderServiceImpl(CrmWorkOrderDao dao) {
		this.dao = dao;
	}
	
	public boolean push(String activityUID, String houseNumber,
			String houseLocation, String contactPerson, String contactPhoneNo,
			String dutyPerson, String workDescription, String workPriority,
			String workStatus, String plannedCompletion, String comment,
			String srno, String createPerson) {
		
		logger.info("推送客服工单：" + activityUID + "|" + houseNumber + "|" + houseLocation + "|" + contactPerson
				 + "|" + contactPhoneNo + "|" + dutyPerson + "|" + workDescription + "|" + workPriority
				 + "|" + workStatus + "|" + plannedCompletion + "|" + comment
				 + "|" + srno + "|" + createPerson);
		
		String iStatus = "1";
		if ("未处理".equals(workStatus) || workStatus == "未处理") iStatus = "1";
		
		CrmWorkOrder cwo = new CrmWorkOrder();
		
		cwo.setActivityUID(activityUID);
		cwo.setHouseNumber(houseNumber);
		cwo.setHouseLocation(houseLocation);
		cwo.setContactPerson(contactPerson);
		cwo.setContactPhoneNo(contactPhoneNo);
		cwo.setDutyPerson(dutyPerson);
		cwo.setWorkDescription(workDescription);
		cwo.setWorkPriority(workPriority);
		cwo.setWorkStatus(iStatus);
		cwo.setPlannedCompletion(DateUtil.dateParse(plannedCompletion, "MM/dd/yyyy hh:mm:ss"));
		cwo.setComment(comment);
		cwo.setSrno(srno);
		cwo.setContactPerson(createPerson);
		
		Long id = dao.save(cwo);
		if (id > 0)
			return true;
		else
			return false;
	}
}
